package org.gcb.core.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import org.gcb.core.model.util.Utilities;

/**
 *
 * @author Jason
 */
public class Ability {

    public static final String PROP_SCORE = "score";
    public static final String PROP_MISC = "misc";

    private final AbilityType type;
    private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
    private Integer score = 0;
    private Integer misc = 0;

    public Ability(AbilityType type) {
        this.type = type;
    }

    public Integer getScore() {
	//Utilities.retreiveType(Ability.class);
	Integer miscMod = 0;//Utilities.calculateMiscModifier(null);
        return score + miscMod;
    }

    public void setScore(Integer score) {
        Integer oldScore = this.score;
        this.score = score;
        propertyChangeSupport.firePropertyChange(PROP_SCORE, oldScore, this.score);
    }

    public Integer getMisc() {
        return misc;
    }

    public void setMisc(Integer misc) {
        Integer oldMisc = this.misc;
        this.misc = misc;
        propertyChangeSupport.firePropertyChange(PROP_MISC, oldMisc, this.misc);
    }

    public AbilityType getType() {
        return type;
    }

    public Integer getModifier() {
        return (score / 2) - 5 + misc;
    }

    /**
     * Add PropertyChangeListener.
     *
     * @param listener
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    /**
     * Remove PropertyChangeListener.
     *
     * @param listener
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }
}
